/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __PONY_AT24CXX_H__
#define __PONY_AT24CXX_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
#include <x_config.h>
#include <hal_mtd.h>
/* includes (local) ----------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/

#if CONFIG_AT24CXX_SIZE == 2 /* AT24C02: 2Kbits = 256; 32 * 8 =  256 */
#define AT24CXX_NPAGES   32
#define AT24CXX_PAGESIZE 8
#define AT24CXX_ADDRSIZE 1
#elif CONFIG_AT24CXX_SIZE == 4 /* AT24C04: 4Kbits = 512B; 32 * 16 = 512 */
#define AT24CXX_NPAGES   32
#define AT24CXX_PAGESIZE 16
#define AT24CXX_ADDRSIZE 1
#elif CONFIG_AT24CXX_SIZE == 8 /* AT24C08: 8Kbits = 1KiB; 64 * 16 = 1024 */
#define AT24CXX_NPAGES   64
#define AT24CXX_PAGESIZE 16
#define AT24CXX_ADDRSIZE 1
#elif CONFIG_AT24CXX_SIZE == 16 /* AT24C16: 16Kbits = 2KiB; 128 * 16 = 2048 */
#define AT24CXX_NPAGES   128
#define AT24CXX_PAGESIZE 16
#define AT24CXX_ADDRSIZE 1
#else
#error "Unsupported AT24CXX size"
#endif

#define AT24CXX_NR_BYTES (AT24CXX_NPAGES * AT24CXX_PAGESIZE)

/* typedefs ------------------------------------------------------------------*/
/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __PONY_AT24CXX_H__ */
